<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib  prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib  prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="defaultImg" value="${redis:getSysConfig('website_default_img')}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>自营店铺商品信息</title>
	<jsp:include page="../../../util/import.jsp"/>
	<style>
	pre {
    background-color: transparent;
     border: 0;
}
	</style>
	<script type="text/javascript">
        /**
         * 初始化Table
         */
        $(function(){
            var $tt= $("#tt").bootstrapTable({
                url:"${basePath}/back/shopProduct/queryProductList.sjson",  /**请求后台的URL（*）**/
                method: 'post',                       	/**请求方式（*）**/
                contentType: "application/x-www-form-urlencoded",
                dataType: 'json',
                toolbar: '#toolbar',               	    /**工具按钮用哪个容器**/
                striped: true,                      	/**是否显示行间隔色**/
                cache: false,                       	/**是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）**/
                pagination: true,                   	/**是否显示分页（*）**/
                sortable: false,                    	/**是否启用排序**/
                sortOrder: 'asc',                   	/**排序方式**/
                queryParamsType: '',
                sidePagination: 'server',           	/**分页方式：client客户端分页，server服务端分页（*）**/
                pageNumber: 1,
                pageSize:10,							/**初始化加载第一页，默认第一页**/
                pageList: [5,10, 25, 50],        	    /**可供选择的每页的行数（*）**/
                search: false,                       	/**是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大**/
                strictSearch: true,
                showColumns: true,                  	/**是否显示所有的列**/
                showRefresh: true,                  	/**是否显示刷新按钮**/
                minimumCountColumns: 2,             	/**最少允许的列数**/
                clickToSelect: true,                	/**是否启用点击选中行**/
                uniqueId: 'productId',   	/**每一行的唯一标识，一般为主键列**/
                singleSelect  : true,                   /** 单选checkbox**/
                showToggle:false,                    	/**是否显示详细视图和列表视图的切换按钮**/
                cardView: false,                    	/**是否显示详细视图**/
                detailView: false,                  	/**是否显示父子表**/
                columns: [
                    {checkbox: true},
                    {field: 'Number', title: '编号',align: 'center',valign: 'middle',width:'50px',formatter: function (value, row, index) {
                        var page = $tt.bootstrapTable("getPage");
                        return page.pageSize * (page.pageNumber - 1) + index + 1;
                    }
                    },
                    {field: 'productId',title: '商品主键ID',align: 'center',valign: 'middle'},
                    {field: 'sku',title: 'SKU号',align: 'center',valign: 'middle'},
                    {field:"logoImg",title:"商品图片",align: 'center',valign: 'middle',formatter:function(value,row,index){
                        var imgHtml='<div><a  data-toggle="modal" data-target="#detailModal" href="#" mce_href="#" ';
                        imgHtml+='onclick="showListRebackImage(' + index + ',1,1),detailInfo(' + row.productId + ')">';
                        imgHtml+='<img id="uploadImg_' + index + '" class="uploadImg"';
                        imgHtml+='onMouseOver="showListBigImage(' + index + ',4,4,0,-40)"';
                        imgHtml+='onMouseOut="showListRebackImage(' + index + ',1,1)"  src="${uploadPath}/' + value+ '" ';
                        imgHtml+='onerror="this.src=\'${srcPath}/common/images/mrbj.png\'"  width="30px" height="30px"/></a></div>';
                        return imgHtml;
                    }
                    },
                    {field: 'productFullName',title: '商品名称',align: 'center',valign: 'middle', formatter: function (value,row,index) {
							var a_html = '<pre><a data-toggle="modal" data-target="#detailModal" href="#" mce_href="#" onclick="detailInfo(' + row.productId + ')">' + row.productFullName + '</a></pre>';
							return a_html;
                    	}
                    },
                    {field: 'sortName',title: '所属商品分类',align: 'center',valign: 'middle'},
                    {field:"shopName",title:"店铺名称",align: 'center',valign: 'middle'},
					/*  {field: 'imageType',title: '图片/视频',align: 'center',valign: 'middle', formatter: function (value,row,index) {
					 if (value=="1") {
					 return "图片";
					 } else if(value =="2") {
					 return "视频";
					 }else{
					 return "其他";
					 }
					 }
					 },*/
					/* {field: 'productCode',title: '商品编号',align: 'center',valign: 'middle'},*/
                    {field: 'marketPrice',title: '市场价（元）',align: 'center',valign: 'middle'},
                    {field:"salesPrice",title:"销售价格（元）",align: 'center',valign: 'middle'},
                    {field:"salesPriceBack",title:"批发价格（元）",align: 'center',valign: 'middle'},
                    {field:"storeNumber",title:"库存数",align: 'center',valign: 'middle'},
                    {field:"isPutSale",title:"是否上架",align: 'center',valign: 'middle',formatter:function(value,row,index){
                        if(value=="1"){ return "<font class='color_002'>未上架</font>";}
                        if(value=="2"){ return "<font class='color_001'>已上架</font>";}
                        if(value=="3"){ return "<font class='color_003'>违规下架</font>";}
                    }
                    },
                    {field:"isRecommend",title:"是否推荐",align: 'center',valign: 'middle',formatter:function(value,row,index){
                        if(value=="1"){ return "<font class='color_001'>是</font>";}
                        if(value=="0"){ return "<font class='color_002'>否</font>";}
                    }
                    },
                    {field:"isPass",title:"审核状态",align: 'center',valign: 'middle',formatter:function(value,row,index){
                        if(value=="0"){
                            return "<font class='color_002'>未通过</font>";
                        }else if(value=="1"){
                            return "<font class='color_001'>已通过</font>";
                        }else if(value=="2"){
                            return "<font class='color_003'>待申请</font>";
                        }else if(value=="3"){
                            return "<font class='color_004'>待审核</font>";
                        }
                    }
                    },
					/* {field:"isShow",title:"是否显示在列表",align: 'center',valign: 'middle',
					 formatter: function (value, row, index) {
					 if(value=="1"){ return "<font class='color_001'>显示</font>";}
					 if(value=="0"){ return "<font class='color_002'>不显示</font>";}
					 }
					 },*/
                    {field: 'createDate',title: '创建时间',align: 'center',valign: 'middle',
                        formatter:function(value,row,index){
                            return  toJsonDate(value,"yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {field:"passUserName",title:"审核人名称",align: 'center',valign: 'middle'}
                ],
                queryParams: function (params) {
                    /**特别说明，返回的参数的值为空，则当前参数不会发送到服务器端,这种指定请求参数的方式和datatables控价类似**/
                    params.shopInfoProductType = '${shopInfoProductType}';
                    params.productName = $("#q_productName").val();
                    params.sku = $("#q_sku").val();
                    params.isPass = $("#q_isPass").val();
                    params.isPutSale = $("#q_isPutSale").val();
					/* params.imageType = $("#q_imageType").val();*/
                    params.currentPage = params.pageNumber;
                    return params;
                }
            });
        });

	<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_delete">
        /**
         * 删除商品
         */
        function deleteProduct(){
            /**获取选中行的id**/
            var selectedRow = $("#tt").bootstrapTable('getSelections');
            /**判断是否选中一行**/
            if (selectedRow.length == 1) {
                /**获取选中行的商品Id**/
                var productId = selectedRow[0].productId;
                showConfirm("您确定要删除商品吗？", function() {
                    $.ajax({
                        type: "POST",
                        dataType: "JSON",
                        url: "${basePath}/back/shopProduct/deleteProductAll.sjson",
                        data: {productId:productId},
                        success: function (data) {
                            if(data.success){
                                $("#tt").bootstrapTable('refresh');
                            }
                        }
                    });
                });
            } else {
                showMsg("请选择一行记录！");
            }
        }
	</shiro:hasPermission>

	<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_checked">
        /**
         * 审核自营店铺商品
         */
        function auditProduct(){
            /**获取选中行的id**/
            var selectedRow = $("#tt").bootstrapTable('getSelections');
            /**判断是否选中一行**/
            if (selectedRow.length == 1) {
                var isPass=selectedRow[0].isPass;
                /**商品处于待申请状态：2 时不可审核**/
                if(isPass!='2' && isPass !=2){
					/**获取选中行的商品Id**/
					var productId = selectedRow[0].productId;
					$("#auditModalLabel").text("自营店铺商品审核");
					$("#btn_audit").attr("data-target", "#auditModal");/**选中了记录后才可打开对应的模态框**/
					$.ajax({
						type: "POST",
						dataType: "JSON",
						url: "${basePath}/back/shopProduct/getShopProductAndRelationInfoByProductId.sjson",
						data: {productId:productId},
						success: function (data) {
							var productInfo = data.productInfo;
							$("#a_isShow_"+productInfo.isShow).attr("checked",true); //回显是否显示
							$("#a_productId").val(productInfo.productId); //回显商品Id
							$("#a_isPutSale_"+productInfo.isPutSale).attr("checked",true); //回显上架状态
							$("#a_isPass_"+productInfo.isPass).attr("checked",true); //回显审核状态
							$("#a_isNew_"+productInfo.isNew).attr("checked",true); //回显是否为新品
							$("#a_isHot_"+productInfo.isHot).attr("checked",true); //回显是否热销
							$("#a_isRecommend_"+productInfo.isRecommend).attr("checked",true); //回显是否推荐
							if(productInfo.isPass==0){
								$("#auditComment").val(productInfo.auditComment);
								$("#btMessage").html("<i style='color:red'>*</i>&nbsp;&nbsp;");
							}else{
								$("#btMessage").html("");
							}
							changeIsPass(productInfo.isPass);
							if(Number(productInfo.isPass)<3){//审核过
								document.getElementById("a_isPass_3").disabled="disabled";
							}else{
								document.getElementById("a_isPass_3").disabled="";
							}
						}
					});
				}else{
                    showMsg("未申请商品不可审核！");
                }
            } else {
                showMsg("请选择一行记录！");
            }
        }
	</shiro:hasPermission>

	<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_updateRatio">
        /**
         * 修改商品的返佣比例
         */
        function updateRatio(){
            /**获取选中行的id**/
            var selectedRow = $("#tt").bootstrapTable('getSelections');
            /**判断是否选中一行**/
            if (selectedRow.length == 1) {
                /**获取选中行的商品Id**/
                var productId = selectedRow[0].productId;
                $("#updateModalLabel").text("修改返利比例");
                reValidateUpdateTatioForm();
                $("#btn_update").attr("data-target", "#updateModal");/**选中了记录后才可打开对应的模态框**/
                $.ajax({
                    type: "POST",
                    dataType: "JSON",
                    url: "${basePath}/back/shopProduct/getShopProductAndRelationInfoByProductId.sjson",
                    data: {productId:productId},
                    success: function (data) {
                        var productInfo = data.productInfo;
                        $("#ur_upRatio").val(productInfo.upRatio);
                        $("#ur_secRatio").val(productInfo.secRatio);
                        $("#ur_thiRatio").val(productInfo.thiRatio);
                        $("#ur_productId").val(productInfo.productId);
                    }
                });
            }else {
                showMsg("请选择一行记录！");
            }
        }
	</shiro:hasPermission>

	<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_pGeneratedQrCode">
        /**
         * 批量生成入驻店铺商品的二维码
         */
        function bactchGeneratedQrCode(){
            showConfirm("您确定要重新生成二维码吗？", function() {
                showMsg("二维码生成中,请耐心等待！");
                $.ajax({
                    type: "POST", dataType: "JSON",
                    url: "${basePath}/back/shopProduct/productInfoGeneratedQrCode.sjson",
                    data: {shopInfoProductType:"1"},//1、平台基础商品；2 、平台店铺商品
                    success: function(data){
                        /** 自动关闭弹出模态框窗口**/
                        $(".close").click();
                        var failureLog2=data.failureLog2;
                        var failureLog1=data.failureLog1;
                        if(data.success){
                            $("#tt").bootstrapTable('refresh');
                            showMsg("二维码已生成！");
                        }else{
                            if(failureLog1!=null&&failureLog1!=""){
                                showMsg(failureLog1);
                            }else if(failureLog2!=null&&failureLog2!=""){
                                showMsg(failureLog2);
                            }else{
                                showMsg("生成二维码失败！");
                            }
                        }
                    }
                });
            });
        }
	</shiro:hasPermission>

	<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_evaluateGoods">
        /**
         * 查询评价信息
         */
        function evaluateGoods(){
            /**获取选中行的id**/
            var selectedRow = $("#tt").bootstrapTable('getSelections');
            /**判断是否选中一行**/
            if (selectedRow.length == 1) {
                location.href="${basePath}/back/shopProduct/gotoProEvaluateGoods.sjson?productId="+selectedRow[0].productId;
            }else {
                showMsg("请选择一行记录！");
            }
        }
	</shiro:hasPermission>

	<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_relationProduct">
        /**
         * 查看关联推荐商品
         */
        function relationProduct(){

        }
	</shiro:hasPermission>
	</script>
</head>
<body >
<div class="panel-body" id="customer-main-panel">
	<!-- 查询条件 -->
	<div class="panel panel-default">
		<div class="panel-heading">商品信息查询</div>
		<div class="panel-body">
			<form id="qform" class="form-horizontal">
				<div class="form-group" style="margin-top:15px">
					<div class="col-sm-3" style="width: 230px;">
						<div class="input-group input-group-sm">
							<span class="input-group-addon">商品名称</span>
							<input type="text" class="form-control" id="q_productName" name="productName" placeholder="请输入商品名称"/>
						</div>
					</div>
					<div class="col-sm-3" style="width: 200px;">
						<div class="input-group input-group-sm">
							<span class="input-group-addon">SKU</span>
							<input type="text" class="form-control" id="q_sku" name="sku" placeholder="请输入SKU"/>
						</div>
					</div>
					<div class="col-sm-2" style="width: 190px;">
						<div class="input-group input-group-sm">
							<span class="input-group-addon">审核状态</span>
							<select id="q_isPass" name="isPass" class="form-control">
								<option value="">请选择</option>
								<option value="0">未通过</option>
								<option value="1">已通过</option>
								<option value="2">待申请</option>
								<option value="3">待审核</option>
							</select>
						</div>
					</div>
					<div class="col-sm-2" style="width: 190px;">
						<div class="input-group input-group-sm">
							<span class="input-group-addon">是否上架</span>
							<select id="q_isPutSale" name="isPutSale" class="form-control">
								<option value="">请选择</option>
								<option value="1">未上架</option>
								<option value="2">已上架</option>
							</select>
						</div>
					</div>
					<%--<div class="col-sm-2" style="width: 190px;">
						<div class="input-group input-group-sm">
							<span class="input-group-addon">图片/视频</span>
							<select id="q_imageType" name="imageType" class="form-control">
								<option value="">请选择</option>
								<option value="1">图片</option>
								<option value="2">视频</option>
							</select>
						</div>
					</div>--%>
					<div class="col-sm-2">
						<button type="button" id="btn_query" class="btn btn-primary">查询</button>&nbsp;&nbsp;
						<button type="reset" class="btn btn-success" id="resetBtn">重置</button>
					</div>
				</div>
			</form>
		</div>
	</div>

	<!-- 工具栏 -->
	<div id="toolbar" class="btn-group">
		<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_add">
			<button id="btn_add" type="button" class="btn btn-default" data-toggle="modal" data-target="#selectShopInfoModal" onclick="showSelectShopInfo()">
				<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
			</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_update">
			<button id="btn_edit" type="button" class="btn btn-default" data-toggle="modal"  onclick="editInfo()">
				<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
			</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_delete">
			<button id="btn_delete" type="button" class="btn btn-default" onclick="deleteProduct()">
				<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
			</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_checked">
			<button id="btn_audit" type="button" class="btn btn-default" data-toggle="modal"  onclick="auditProduct()">
				<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>审核
			</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_updateRatio">
			<button id="btn_update" type="button" class="btn btn-default" data-toggle="modal"  onclick="updateRatio()">
				<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改返利比例
			</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_pGeneratedQrCode">
			<button id="btn_create" type="button" class="btn btn-default"  onclick="bactchGeneratedQrCode()">
				<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>批量生成二维码
			</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_evaluateGoods">
			<button id="btn_searchEvaluate" type="button" class="btn btn-default"  onclick="evaluateGoods()">
				<span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询评价信息
			</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="back_gotoSelfSupportShopProductListPage_relationProduct">
			<button id="btn_search_relation" type="button" class="btn btn-default"  onclick="relationProduct()">
				<span class="glyphicon glyphicon-search" aria-hidden="true"></span>查看关联推荐商品
			</button>
		</shiro:hasPermission>
	</div>

	<!-- 渲染的table -->
	<table id="tt"></table>

	<!-- 选择店铺列表页面 -->
	<jsp:include page="selectShopInfoList.jsp"/>

	<!-- 添加修改页面 -->
	<jsp:include page="addOrEdit_product.jsp"/>

	<!-- 添加图片上传页面 备注：此模态框只能放在此处，否则关闭模态框会关闭addOrEdit.jsp的模态框-->
	<jsp:include page="images_add.jsp"/>

	<!-- 商品审核页面 -->
	<jsp:include page="audit_product.jsp"/>

	<!-- 修改商品返利比例页面 -->
	<jsp:include page="ratio_update.jsp"/>

	<!-- 详情页面 -->
	<jsp:include page="detail_product.jsp"/>
</div>
</body>
</html>
